package com.my.leetcode;

import java.util.*;

public class Student implements Comparable<Student> {


    private String name;

    private int age;

    private int score;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }


    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public int compareTo(Student o) {
        return this.name.compareTo(o.name);
    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    public static void main(String[] args) {

        Student student = new Student("Zlx", 29, 80);
        Student student2 = new Student("Clock", 17, 90);
        Student student3 = new Student("Alice", 20, 85);
        Student student4 = new Student("Bob", 32, 99);

        List<Student> students = Arrays.asList(student, student2, student3, student4);

        System.out.println(students);

        Collections.sort(students);

        System.out.println("根据name进行排序：" + students);


        Collections.sort(students, new StudentSortByAga());
        System.out.println("根据age进行排序：" + students);


        Collections.sort(students, new StudentSortByScore());
        System.out.println("根据score进行排序：" + students);
    }




    static class StudentSortByAga implements Comparator<Student>{

        @Override
        public int compare(Student o1, Student o2) {
            return o1.age - o2.age;
        }
    }


    static class StudentSortByScore implements Comparator<Student>{

        @Override
        public int compare(Student o1, Student o2) {
            return o1.score - o2.score;
        }
    }

}


